package connect2congress.client;

import com.google.gwt.widgetideas.graphics.client.Color;
import connect2congress.client.legacy.Point;
import connect2congress.client.properties.C2CDate;

/**
 * Created by IntelliJ IDEA.
 * User: peter
 * Date: Mar 3, 2010
 * Time: 5:24:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class Tick implements Comparable<Tick>{

    public C2CDate vd;
    private int type;

    public Point loc;
    public double width;
    public double height = 2;
    public static final Color SELECTED_VERB_COLOR = new Color(0,255,0);
    public static final Color UNSELECTED_VERB_COLOR = new Color(230,255,255);
    public static final Color SELECTED_WNOM_COLOR = new Color(255,0,0);
    public static final Color UNSELECTED_WNOM_COLOR = new Color(255,255,230);

    private boolean isSelected;

    private double magnitude;

    public Color tickFill;


    public Tick(C2CDate vd,double w, double h, int type) {
        //System.out.println("Making a new tick");
        this.vd = vd;
        setSelected(false);
        this.magnitude = vd.getMagnitude();
        width = magnitude;
        height = h/2;
        this.type = type;

    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Color getFillStyle() {

        return tickFill;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;

        if(type == Connect2Congress.VERB_TYPE) {
            if(isSelected) {
                tickFill = Tick.SELECTED_VERB_COLOR;
            } else {
                tickFill = Tick.UNSELECTED_VERB_COLOR;
            }
        } else if(type == Connect2Congress.WNOM_TYPE) {
            if(isSelected) {
                tickFill = Tick.SELECTED_WNOM_COLOR;
            } else {
                tickFill = Tick.UNSELECTED_WNOM_COLOR;
            }
        }
    }

    public double getWidth() {
        return width;
    }
    public long getDate() {
        return vd.getDate();
    }
    public void setWidth(double width) {
        this.width = magnitude*100/width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height/2;
    }

    public double getMagnitude() {
        return magnitude;
    }

    public double getWidth(double w) {
        return width;
    }
    public double getHeight(double h) {
        return h;
    }

    public int compareTo(Tick o) {
        return (int) (this.getDate() - o.getDate());
    }

    /*public boolean under(int x, int y) {
       if(loc.x + width >= x && loc.x <= x && loc.y + height >= y && loc.y <= y) {
           //System.out.println("Mouse Clicked on: " + this.vd.getDate());
           return true;
       } else return false;
   } */
}
